home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_130 / patedit / patedit.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  152 lines

  1. /* The code in this module is almost straight from PowerWindows example
  2.    which they say is in no way copyrighted and free to use.  Incidentally
  3.    it is a very good example of a clean event handler. /*
  4.  
  5. /* ******************** Enthusiastic Product Endorsement *************** */
  6.  
  7. /* I think Power Windows is the greatest Amiga programming tool on the
  8.        market.  It makes it EASY to produce great-looking programs that
  9.        make full use of the Intuition environment. */
  10.  
  11. /* INCLUDES ********************************************************** */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/io.h>
  15. #include <exec/memory.h>
  16. #include <libraries/dos.h>
  17. #include <intuition/intuition.h>
  18. #include <libraries/dosextens.h>
  19.  
  20.    USHORT quit_flag = FALSE;
  21.  
  22. /* This is for the event handler */
  23. void quit(object)
  24. APTR object;
  25. {
  26.    quit_flag = TRUE;
  27. }
  28.  
  29. SHORT mousex, mousey;
  30.  
  31. struct IntuitionBase *IntuitionBase;
  32. struct GfxBase *GfxBase;
  33.  
  34.  
  35. /* get the PowerWindows 2.0 code */
  36. #include "PatEdit.h"
  37.  
  38.    struct Window *wG;  /* we fetch the RastPort pointer from here */
  39.    struct RastPort *rpG;
  40. struct Process *OurTask;
  41. struct Window  *old_pr_WindowPtr;
  42.  
  43. static char    def_name[50] = "Meps";
  44. static char    def_dir[50] = "df1:";
  45.  
  46. #ifdef NEWSCREENSTRUCTURE
  47.    struct Screen *sC;
  48.    struct ViewPort vP;
  49. #endif
  50. main()
  51. {
  52.    UWORD code;
  53.    ULONG class;
  54.    APTR object;
  55.  
  56.    struct IntuiMessage *message;   /* the message the IDCMP sends us */
  57.  
  58.    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0L);
  59.    if (IntuitionBase == NULL)
  60.    {
  61.        printf("intuition is not here.  where are we?\n");
  62.        goto cleanup1;
  63.    }
  64.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L);
  65.  
  66. #ifdef NEWSCREENSTRUCTURE
  67.    sC = OpenScreen(&NewScreenStructure);   /* open screen if present */
  68.    NewWindowStructure1.Screen = sC;
  69. #ifdef PALETTE
  70.  
  71. /* note *** the original PW example had a bug here, since it failed to
  72.    coerce the PaletteColorCount variable to long (made a wierd bug) */
  73.    
  74.    LoadRGB4(&sC->ViewPort ,&Palette,(long)PaletteColorCount);
  75. #endif
  76. #endif
  77.  
  78.    wG = OpenWindow(&NewWindowStructure1);  /* open the window */
  79.    if ( wG == NULL )
  80.    {
  81.        printf ("open window failed\n");
  82.        goto cleanup1;
  83.    }
  84.  
  85.    rpG = wG->RPort;    /* get a rastport pointer for the window */
  86.  
  87. #ifdef MenuList1
  88.    SetMenuStrip(wG,&MenuList1);    /* attach any Menu */
  89. #endif
  90.  
  91. #ifdef IntuiTextList1
  92.    PrintIText(rpG,&IntuiTextList1,0L,0L);  /* Print the text if there is
  93.                        any */
  94. #endif
  95.  
  96. #ifdef BorderList1
  97.    DrawBorder(rpG,&BorderList1,0L,0L); /* Draw the borders if there are
  98.                        any */
  99. #endif
  100.  
  101. #ifdef ImageList1
  102.    DrawImage(rpG,&ImageList1,0L,0L);   /* Draw the images if there are any */
  103. #endif
  104.  
  105.    init();
  106.    
  107.    do
  108.    {
  109.        WaitPort(wG->UserPort);
  110.            while( (message = (struct IntuiMessage *)
  111.                GetMsg(wG->UserPort) ) != NULL)
  112.            {
  113.                code = message->Code;  /* MENUNUM */
  114.                object = message->IAddress;  /* Gadget */
  115.                class = message->Class;
  116.                mousex=message->MouseX;
  117.                mousey=message->MouseY;
  118.                ReplyMsg(message);
  119.                if ( class == CLOSEWINDOW ) (quit_flag = TRUE);
  120. #ifdef HANDLEEVENT
  121.                if (( class == GADGETUP ) ||    /* Gagdets */
  122.                    ( class == GADGETDOWN ))
  123.                    HandleEvent(object);
  124. #ifdef MenuList1
  125.                if ( class == MENUPICK )    /* MenuItems */
  126.                HandleEvent(ItemAddress(&MenuList1,(LONG)code));
  127. #endif
  128. #endif
  129.                if (class==REQCLEAR) SetSize();
  130.            }
  131.    } while (quit_flag == FALSE);
  132.  
  133. cleanup3:
  134. #ifdef MenuList1
  135.    ClearMenuStrip(wG);
  136. #endif
  137.  
  138. cleanup2:
  139.     if (old_pr_WindowPtr) OurTask->pr_WindowPtr = old_pr_WindowPtr;
  140.  
  141.    CloseWindow(wG);
  142. #ifdef NEWSCREENSTRUCTURE
  143.    CloseScreen(sC);
  144. #endif
  145.  
  146. cleanup1:
  147.    if (GfxBase != NULL) CloseLibrary(GfxBase);
  148.    if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  149.    return(0);
  150.  
  151. }
  152.